﻿
    using Entitas;
    using UnityEngine;

    public class UpdateTimerSystem : IExecuteSystem
    {
        private readonly IGroup<GameEntity> myGroup;

        public UpdateTimerSystem (Contexts contexts)
        {
            myGroup = contexts.game.GetGroup (GameMatcher.TimerComp);
        }
        
        public void Execute ()
        {
            var dt = Time.deltaTime;

            foreach (var entity in myGroup.GetEntities())
            {
                var newTime = Mathf.Max (entity.timerComp.FireTimer - dt,0);
                entity.ReplaceTimerComp (newTime);
            }
        }
    }
